/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package services;


import services.interfaces.IBasketService;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import models.Baskets;
import models.ItemBasket;
import models.Orders;

import models.Products;

/**
 *
 * @author Yaroslav
 */
public class BasketServiceImpl extends GenericServiceImpl<Baskets> implements IBasketService {

   
     
    @PersistenceContext(unitName="ors-ejbPU2")
    private EntityManager em;
    
    public BasketServiceImpl() {
        super(Baskets.class);
    }
    
   
    
     private List<Baskets> listBasket = new ArrayList<Baskets>();
    
    @Override
    public void addItemBasket(Products product, Baskets basket,int count) {
        int i = listBasket.indexOf(basket);
         ItemBasket item = new ItemBasket();
         item.setProduct(product);
         item.setCount(count);
        if (i==-1) {
           
            basket.addItemBasket(item);
            this.listBasket.add(basket);
        }else{
        listBasket.get(i).addItemBasket(item);
        }
         
    }

    @Override
    public void removeItemBasket(ItemBasket item, Baskets basket) {
         int i = listBasket.indexOf(basket);
            if (i==-1) {
                return ;
            }else{
                listBasket.get(i).deleteItemBasket(item);
        }
    }

    @Override
    protected EntityManager getEntityManager() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int count() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void addBasketToOrders(Orders order, Baskets basket) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
